package edu.nd.mobicom.codemonkey.mobilenewscoverage;


import android.os.Bundle;
import android.provider.MediaStore;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.util.Log;
import android.view.Gravity;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import com.parse.ParseException;
import com.parse.LogInCallback;
import com.parse.Parse;
import com.parse.ParseObject;
import com.parse.ParseUser;
import com.parse.PushService;

public class Activity_Welcome extends Activity {

    @Override
    public void onCreate(Bundle savedInstanceState) {
    	Parse.initialize(this, "SeUAymviO4A0SpMUMeUdIIYTAb6rei0zSUqDLPxg", "a7Czpo8wIoUL6cOUA0f8x0tXa25DCimwJLNaV9eq"); 

    	
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_welcome);
        Button nextsignup = (Button) findViewById(R.id.signup_btn);
    
        nextsignup.setOnClickListener(new Button.OnClickListener() {	
			public void onClick(View view) {
				// TODO Auto-generated method stub
				Intent signupIntent = new Intent(view.getContext(), Activity_Signup.class);
				startActivityForResult(signupIntent,0);
			}
		});
        
        Button nextlogin = (Button) findViewById(R.id.login_btn);
        
        nextlogin.setOnClickListener(new Button.OnClickListener(){ 
        	public void onClick(final View view) {
        		EditText uname = (EditText)findViewById(R.id.username);
				EditText pwd = (EditText)findViewById(R.id.password);
				//check if textboxes are empty
					
	//			ParseUser.logInInBackground(uname.getText().toString(), pwd.getText().toString(), new LogInCallback() {
				ParseUser.logInInBackground("hello", "world", new LogInCallback() {
					  public void done(ParseUser user, ParseException e) {
					    if (user != null) {
							Intent mainIntent = new Intent(view.getContext(), Activity_Main.class);
							startActivityForResult(mainIntent,0);
					    } else {
					    	Context context = getApplicationContext();
					    	CharSequence text = "Incorrect login information:";
					    	int duration = Toast.LENGTH_SHORT;

					    	Toast toast = Toast.makeText(context, text, duration);
					    	toast.setGravity(Gravity.CENTER|Gravity.CENTER, 0, 0);
					    	toast.show();
					    }
					  }
					});
        		

        	}
        });
    }


@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.activity_main, menu);
    return true;
}
}